package com.xros.demo.gamedataserver.handler;

import com.alibaba.fastjson.JSONObject;
import com.xros.demo.gamedataserver.domian.message.ChatMessage;
import com.xros.demo.gamedataserver.domian.message.CustomerMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.log4j.Log4j2;

/**
 * @Author: mzp
 * @Description: 消息包装处理器
 * @Date: 2024/3/27 9:37
 * @Version: 1.0
 */
@Log4j2
public class MsgWrapperHandler extends SimpleChannelInboundHandler<Object> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        log.info("收到解析后的消息数据为：{}", JSONObject.toJSONString(msg));

        //region （描述：测试代码块）

        //TODO(时间：2024/6/22 16:57，描述：这里是一个测试代码块，用于测试消息的发送)

        CustomerMessage toSendMsg =  new ChatMessage(){{
            setSenderId(789L);
            setContent("你好，我是沙福林");
            setReceiverId(654L);
        }};

        ctx.channel().writeAndFlush(toSendMsg);

        //endregion

    }
}
